/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author NGOCLINH-PC
 */
public class PrizeType {

    private int PrizeTypeID;
    private String PrizeTypeName;
    private int Status;

    public PrizeType() {
    }

    public PrizeType(int PrizeTypeID, String PrizeTypeName, int Status) {
        this.PrizeTypeID = PrizeTypeID;
        this.PrizeTypeName = PrizeTypeName;
        this.Status = Status;
    }

    public int getPrizeTypeID() {
        return PrizeTypeID;
    }

    public void setPrizeTypeID(int PrizeTypeID) {
        this.PrizeTypeID = PrizeTypeID;
    }

    public String getPrizeTypeName() {
        return PrizeTypeName;
    }

    public void setPrizeTypeName(String PrizeTypeName) {
        this.PrizeTypeName = PrizeTypeName;
    }

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public ArrayList<PrizeType> PTselect() {
        try {
            ArrayList<PrizeType> listPay = new ArrayList<PrizeType>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM PrizeType");
            while (rs.next()) {
                PrizeType pay = new PrizeType(rs.getInt(1), rs.getString(2), rs.getInt(3));
                listPay.add(pay);
            }
            return listPay;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public ArrayList<PrizeType> PTselectById(int id) {
        try {
            ArrayList<PrizeType> listPay = new ArrayList<PrizeType>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM PrizeType where PrizeTypeID='" + id + "'");
            while (rs.next()) {
                PrizeType pay = new PrizeType(rs.getInt(1), rs.getString(2), rs.getInt(3));
                listPay.add(pay);
            }
            return listPay;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public ArrayList<PrizeType> PTselectByStatus() {
        try {
            ArrayList<PrizeType> listPay = new ArrayList<PrizeType>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM PrizeType where Status=1");
            while (rs.next()) {
                PrizeType pay = new PrizeType(rs.getInt(1), rs.getString(2), rs.getInt(3));
                listPay.add(pay);
            }
            return listPay;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static void PTinsert(String PayName, int PayStatus) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("insert into PrizeType values('" + PayName + "','" + PayStatus + "')");
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Insert Successful!");
                //response.sendRedirect("");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void PTupdate(int CateID, String CateName, int CateStatus) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("update PrizeType SET PrizeTypeName='" + CateName + "', Status='" + CateStatus + "' WHERE PrizeTypeID='" + CateID + "'");
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Update Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void PTdelete(int CateID) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("DELETE FROM PrizeType WHERE PrizeTypeID='" + CateID + "'");
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "DELETE Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
